package cn.kailangtu.commontools;

import java.util.Date;

public class DataUtils {
    public static int floatToInt(float source)
    {
        return Math.round(source);
    }

    public static String temperatureFormat(int source)
    {
        float value = (float)source /10f;
        return   String.format("%.1f", value);
    }

    public static int getBit(int source,int bitIndex)
    {
        return (source >> bitIndex) & 0x01;
    }

    public static int[] getBits16(int source)
    {
        int[] result = new int[16];
        for(int i=0;i< 16;i++){
            result[i] = getBit(source,i);
        }

        return result;
    }

    public static byte[] timeToByte6(Date source) {
        byte[] result = new byte[6];
        result[0] = (byte) (source.getYear() - 2000);
        result[1] = (byte) source.getMonth();
        result[2] = (byte) source.getDay();
        result[3] = (byte) source.getHours();
        result[4] = (byte) source.getMinutes();
        result[5] = (byte) source.getSeconds();
        return result;
    }
}
